package com.six.firstpage.controller.api;

import com.six.core.entity.Article;
import com.six.core.vo.Result;
import com.six.firstpage.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-28 16:02
 * @Description:
 */
@Api(value = "/firstpage/api/aritcle", tags = {"链接文章前端Api"})
@RestController
@RequestMapping("/firstpage/api/aritcle")
public class ApiArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "String", name = "navId", value = "", required = true)
    })
    @GetMapping("getArticleByNavId/{navId}")
    public Result getArticleByNavId(@PathVariable String navId){
        Article articlByNavId = articleService.getArticlByNavId(navId);
        return new Result(2000,"查询底部文章成功",articlByNavId);
    }


    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getArticle")
    public Result getArticle(){
        List<Article> allArticle = articleService.getAllArticle();
        return new Result(2000,"查询底部文章成功",allArticle);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Article", name = "article", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addArticle")
    public Result addArticle(@RequestBody Article article){
        Integer integer = articleService.addArticle(article);
        if(integer>=0){
            return new Result(2000,"添加底部文章成功");
        }
        return new Result(5000,"添加底部文章失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Article", name = "article", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateArticle")
    public Result updateArticle(@RequestBody Article article){
        Integer integer = articleService.updateArticle(article);
        if(integer>=0){
            return new Result(2000,"添加底部文章成功");
        }
        return new Result(5000,"添加底部文章失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delArticle/{id}")
    public Result delArticle(@PathVariable Integer id){
        Integer integer = articleService.delArticle(id);
        if(integer>=0){
            return new Result(2000,"添加底部文章成功");
        }
        return new Result(5000,"添加底部文章失败");
    }

}
